<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
   $(function () {
	   setLeaveEditValues();
       var url='${path}/example/leave/edit';
       $('#leaveEditForm').form({
           url : url,
           onSubmit : function() {
               progressLoad();
               var isValid = $(this).form('validate');
               if (!isValid) {
                   progressClose();
               }
               return isValid;
           },
           success : function(result) {
               progressClose();
               result = $.parseJSON(result);
               if (result.success) {
                   showMsg(result.msg);
                   parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                   parent.$.modalDialog.handler.dialog('close');
               } else {
                   var form = $('#leaveEditForm');
                   parent.$.messager.alert('错误', result.msg, 'error');
               }
           }
       });
   })
function setLeaveEditValues(){
    	$.ajax({
    		url:'${ctxPath}/example/leave/findOne',
    		dataType:'json',
    		data:{"id":"${id}"},
    		type:'post',
    		success:function(result){
    			if(!isNull(result)){
    				var tasks=result.tasks;
    				if(!isNull(result.leave)){
    					setFromValues($('#leaveEditForm'),result.leave);
    				}
    				if(!isNull(tasks)){
    				var html='<tr><td style="text-align:right">下一步任务</td><td>';
    					for(var i=0;i<tasks.length;i++){
    						var task=tasks[i];
    						html+='<b>'+task.taskName+'</b>'
                  			+'<input type="hidden" name="'+task.taskDefKey+'_taskType" value="'+task.taskType+'"/>';
                  			if(task.taskType=='assignee'){
                  				html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                  				+'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                  				+'onfocus="selectUser(false,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                  			}
                  			if(task.taskType == 'candidateUser'){
                  				html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                  				+'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                  				+'onfocus="selectUser(true,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                  			} 
                  			if(task.taskType == 'candidateGroup'){
                  				html+='<input type="hidden" name="'+task.taskDefKey+'_candidate_ids" id="'+task.taskDefKey+'_candidate_ids" value="'+task.candidate_ids+'"/>'
                  				+'<input type="text" class="easyui-text-2" name="'+task.taskDefKey+'_candidate_name" id="'+task.taskDefKey+'_candidate_ids_disp"'
                  				+'onfocus="selectRole(true,\''+task.taskDefKey+'_candidate_ids\',\''+task.taskDefKey+'_candidate_ids_disp\')" value="'+task.candidate_name+'"/>';
                  			}
                  			html+='<br /><br />';
    					}
    					html+='</td></tr>';
    					$('#leaveEditForm table').append(html);
    				}
    			}
    		}
    	})
    }

</script>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'center',border:false" style="overflow-x:hidden;overflow-y: auto;padding: 3px;" >
        <form id="leaveEditForm" method="post">
            <table class="grid">
 				<tr>
                      <td style="text-align:right">申请人</td>
                      <td>
                          <input type="hidden" name="id" value="${leave.id}">
                        <input name='userName'   type='text' placeholder='请输入申请人' class='easyui-text-2  span2' value="<shiro:principal property="name" />" readonly="readonly">
                        <input type="hidden" name="userid" value='<shiro:principal property="id" />'/>
                     </td>
                  </tr> <tr>
                     <td style="text-align:right">标题</td>
                      <td>
                        <input name='title' id='title'  type='text' placeholder='请输入标题' class='easyui-text-2  span2' style="width:90%" value="${leave.title}">
                     </td>
                  </tr><tr>
                     <td style="text-align:right">请假时间</td>
                      <td>
                        <input name='leaveDate' id='leaveDate' type='text'  class='easyui-text-2 easyui-datebox  span2 '  style='height: 29px;' value="${leave.leaveDate}">
                     </td>
                     </tr>
                    <tr>
                       <td style="text-align:right">天数</td>
                      <td>
                        <input name='days' id='days'  type='text' placeholder='请输入天数' class='easyui-text-2  span2 easyui-validatebox' data-options="required:true" value="${leave.days}">
                     </td>
                  </tr> 
 				<tr>
                     <td style="text-align:right">请假原因</td>
                      <td>
                        <textarea name="reason" class="easyui-text-2 easyui-validatebox" data-options="required:true" style="height:50px;width:90%">${leave.reason}</textarea>
                     </td>
                  </tr> 
                  <%--  <c:if test="${tasks.size()>0}">
                  	<tr>
                  		<td style="text-align:right">下一步</td>
                  		<td>
                  <c:forEach var="task" items="${tasks}">
                  			<b>${task.taskName}：</b>
                  			<input type="hidden" name="${task.taskDefKey}_taskType" value="${task.taskType}"/>
                  			<c:if test="${task.taskType eq 'assignee'}">
                  			 <c:if test="${task.taskDefKey eq 'modifyApply'}">
                  			 <input type="hidden" name="${task.taskDefKey}_candidate_ids"  value="${leave.userid}"/>
                  			 <input type="hidden"  name="${task.taskDefKey}_candidate_name"  value="${leave.userName}">
                  			 ${leave.userName}<br/>
                  			 <c:if test="${taskDefKey eq 'hrAudit'}">
                  			 	<br/><b>结束</b>
                  			 </c:if>
                  			 </c:if>
                  			 <c:if test="${task.taskDefKey !='modifyApply'}">
                  				<input type="hidden" name="${task.taskDefKey}_candidate_ids" id="${task.taskDefKey}_candidate_ids" value="${task.candidate_ids}"/>
                  				<input type="text" class="easyui-text-2" name="${task.taskDefKey}_candidate_name" id="${task.taskDefKey}_candidate_ids_disp" 
                  				onfocus="selectUser(false,'${task.taskDefKey}_candidate_ids','${task.taskDefKey}_candidate_ids_disp')" value="${task.candidate_name}"/>
                  				 </c:if>
                  			</c:if>
                  			<c:if test="${task.taskType eq 'candidateUser'}">
                  				<input type="hidden" name="${task.taskDefKey}_candidate_ids" id="${task.taskDefKey}_candidate_ids" value="${task.candidate_ids}"/>
                  				<input type="text" class="easyui-text-2" name="${task.taskDefKey}_candidate_name" id="${task.taskDefKey}_candidate_ids_disp" 
                  				onfocus="selectUser(true,'${task.taskDefKey}_candidate_ids','${task.taskDefKey}_candidate_ids_disp')" value="${task.candidate_name}"/>
                  			</c:if>
                  			<c:if test="${task.taskType eq 'candidateGroup'}">
									<input type="hidden" name="${task.taskDefKey}_candidate_ids"
										id="${task.taskDefKey}_candidate_ids" />
									<input type="text" class="easyui-text-2"
										name="${task.taskDefKey}_candidate_name"
										id="${task.taskDefKey}_candidate_ids_disp"
										value="${task.candidate_ids}"
										onfocus="selectRole(true,'${task.taskDefKey}_candidate_ids','${task.taskDefKey}_candidate_ids_disp')"
										value="${task.candidate_name}" />
								</c:if>
                  			<br /><br />
                  </c:forEach>
                 
                  		</td>
                  	</tr>
                  	</c:if> --%>
            </table>
        </form>
    </div>
</div>